<%--
  Created by IntelliJ IDEA.
  User: yangbushudemao
  Date: 2021/5/4
  Time: 11:54
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@include file="/common/common.jsp" %>
<html>
<head>
    <title>zhuce</title>
</head>
<body>
<div class="container-fluid">
    <div class="panel panel-primary" style="width:900px">
        <div class="panel-heading">
            <H1>注册页面</H1>
        </div>
        <div class="panel-body">
            <form id="loginForm">
                <div class="form-group">
                    <label for="uname">账号</label>
                    <input type="text" class="form-control" name="uname" id="uname"
                           placeholder="请输入账号">
                    <div id="tips"></div>
                </div>
                <div class="form-group">
                    <label for="pwd">密码</label>
                    <input type="password" class="form-control" name="pwd" id="pwd">
                </div>
                <div class="form-group">
                    <label class="col-sm-2 control-label">文件</label>
                    <div class="col-sm-10">
                        <input type="text" name="uimg">
                        <input type="file" id="myFile" name="myFile">
                    </div>
                </div>
            </form>
        </div>
        <div class="panel-footer">
            <input type="button" value="注册" onclick="zhuce()">
        </div>
    </div>
</div>
</body>
</html>
<script>
    function zhuce() {
        $.ajax({
            url: "<%=path%>/UserController/tozhuce",
            type: "post",
            data: $("#loginForm").serialize(),
            datatype: "json",
            async: false,
            success: function (canshu) {
                if (canshu == 1) {
                    alert("zengjia 成功返回到denglu页面");
                    location.href = "<%=path%>";
                } else if (canshu == 2) {
                    alert("账户存在");
                    return;
                }
            },
            error: function () {
                alert("增加失败")
            }
        })
    }

    $("#myFile").fileinput({
        language: 'zh',//汉化
        uploadUrl: "<%=path%>/file/uploadFile",//上传地址
        //showCaption: true,//是否展示显示框
        //showUpload: true,//默认为true, false不显示上传按钮
        //showRemove: true,//默认为true,false不显示移除按钮
        //showClose: true,//默认为true, false不显示图片右上角的关闭按钮
        browseClass: 'btn btn-primary',
        //showPreview: true,
        //showUploadedThumbs: true
        //showBrowse:["txt",""],
        //autoReplace:true,
        allowedFileExtensions: ['jpg', 'png', 'gif', 'txt', 'pdf', 'xls', 'xlsx'], //限制文件上传类型
        maxFileSize: 2048,//设置文件上传大小 单位kb
        maxFileCount: 1,//最大上传数量
        enctype: "multipart/form-data"
    });

    //上传成功回调
    $("#myFile").on('fileuploaded', function (event, data, previewId, index) {
        if (data.response != null) {
            $("[name=uimg]").val(data.response.imgUrl);//abc.jpg  + "," + bcd.jpg
        }
    })
</script>
